<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择教学用品')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <input type="hidden" id="ids" th:value="${ids}"/>
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>名称：</label>
                                <input type="text" name="name" placeholder="请输入名称"/>
                            </li>
                            <li>
                                分类：<select name="type" th:with="type=${@dict.getType('tenant_teach_goods_type')}" class="form-control">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictValue}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                           <!-- <li th:if="${@permission.hasPermi('system:superAdmin:opt')} != 'hidden'">
                                租户：<select name="tenantId" id="tenantId"  class="form-control">
                                    <option value="">所有</option>
                                    <option th:each="t : ${tenantList}" th:text="${t.tenantName}" th:value="${t.tenantId}"></option>
                                </select>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var superAdminFlag = [[${@permission.hasPermi('system:superAdmin:opt')}]];
        var prefix = ctx + "system/common";

        $(function() {
            var options = {
                url: prefix + "/tenantGoods",
                modalName: "教学用品",
                sortName: "id",
                sortOrder: "desc",
                columns: [{
                    checkbox: true,
                    formatter:function (value, row, index) {
                        var ids = $("#ids").val();
                        if (ids) {
                            var arr = ids.split(',');
                            for (var i = 0; i < arr.length; i++) {
                                if (arr[i] == row.id) {
                                    return { checked: true };
                                }
                            }
                        }
                        return { checked: false };
                    }
                },
                {
                    visible: false,
                    field: 'id',
                    title: '教学物品编号'
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'unit',
                    title: '单位'
                },
                {
                    field: 'type',
                    title: '分类'
                },
                {
                    field: 'price',
                    title: '单价'
                }]
            };
            $.table.init(options);
        });

        function submitHandler() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var ids = rows.join();
            parent.chooseGoodsIds(ids);
            $.modal.close();
        }
    </script>
</body>
</html>